/* SPDX-License-Identifier: GPL-2.0+ */
/*
 * Copyright 2025 ASPEED Technology Inc.
 */

#ifndef _CPTRA_H
#define _CPTRA_H

#define IPC_CHANNEL_1_BOOTMCU_IN_ADDR		        0xB1880000
#define IPC_CHANNEL_1_BOOTMCU_OUT_ADDR		        0xB1980000
#define IPC_CHANNEL_1_NS_CA35_IN_ADDR		        0x431880000
#define IPC_CHANNEL_1_NS_CA35_OUT_ADDR		        0x431980000
#define SHARED_MEM_SIZE				        0x100000

#define MBOX_BOOTMCU_DEVICE_NAME		        "mbox-bootmcu-1"

enum cptra_ipc_cmd {
	CPTRA_IPCCMD_ECDSA384_SIGNATURE_VERIFY = 0,
	CPTRA_IPCCMD_SHA384_DIGEST,
	CPTRA_IPCCMD_SHA384_INIT,
	CPTRA_IPCCMD_SHA384_UPDATE,
	CPTRA_IPCCMD_SHA384_FINAL,
	CPTRA_IPCCMD_LMS_SIGNATURE_VERIFY,
	CPTRA_IPCCMD_CALIPTRA_FW_LOAD,
	CPTRA_IPCCMD_STASH_MEASUREMENT,
	CPTRA_IPCCMD_QUOTE_PCRS,
	CPTRA_IPCCMD_GET_IDEV_CERT,
	CPTRA_IPCCMD_GET_IDEV_INFO,
	CPTRA_IPCCMD_POPULATE_IDEV_CERT,
	CPTRA_IPCCMD_GET_LDEV_CERT,
	CPTRA_IPCCMD_GET_FMC_ALIAS_CERT,
	CPTRA_IPCCMD_GET_RT_ALIAS_CERT,
	CPTRA_IPCCMD_INVOKE_DPE_COMMAND,
	CPTRA_IPCCMD_DISABLE_ATTESTATION,
	CPTRA_IPCCMD_FW_INFO,
	CPTRA_IPCCMD_DPE_TAG_TCI,
	CPTRA_IPCCMD_DPE_GET_TAGGED_TCI,
	CPTRA_IPCCMD_INCREMENT_PCR_RESET_COUNTER,
	CPTRA_IPCCMD_EXTEND_PCR,
	CPTRA_IPCCMD_ADD_SUBJECT_ALT_NAME,
	CPTRA_IPCCMD_CERTIFY_KEY_EXTENDED,
	CPTRA_IPCCMD_FIPS_VERSION,
	CPTRA_IPCCMD_SHUTDOWN,
	CPTRA_IPCCMD_CAPABILITIES,
	CPTRA_IPCCMD_SET_AUTH_MANIFEST,
	CPTRA_IPCCMD_AUTHORIZE_AND_STASH,
	CPTRA_IPCCMD_GET_FMC_ALIAS_CSR,
	CPTRA_IPCCMD_SIGN_WITH_EXPORTED_ECDSA,
	CPTRA_IPCCMD_REVOKE_EXPORTED_CDI_HANDLE,
};

enum cptra_ipc_rx_type {
	CPTRA_IPC_RX_TYPE_INTERNAL = 0,
	CPTRA_IPC_RX_TYPE_EXTERNAL = 1,
};

int cptra_ipc_trigger(enum cptra_ipc_cmd cmd);
int cptra_ipc_receive(enum cptra_ipc_rx_type type, void *output, int output_size);
int cptra_stash_measurement(char *metadata, uint8_t *hash, int hash_len);

struct cptra_stash_measurement_ia {
	uint8_t metadata[4];
	uint8_t measure[48];
	uint8_t context[48];
	uint32_t svn;
};

struct cptra_stash_measurement_oa {
	uint32_t chksum;
	uint32_t fips_status;
	uint32_t dpe_result;
};

#endif /* _CPTRA_H */
